package com.example.livedatatest;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import com.example.livedatatest.NetWork.ApiResponse;
import com.example.livedatatest.NetWork.ApiService;
import com.example.livedatatest.NetWork.Viewmodel;
import com.google.gson.Gson;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = findViewById(R.id.btn);
//        button.setOnClickListener(v -> getdata());
        Viewmodel viewmodel = new ViewModelProvider(this).get(Viewmodel.class);
        LiveData<User> liveData = viewmodel.getuser();
        liveData.observe(MainActivity.this, new Observer<User>() {
            @Override
            public void onChanged(User user) {
                TextView txt = findViewById(R.id.txt);
                txt.setText(new Gson().toJson(user));
            }
        });
    }
//    private void getdata(){
//        ApiService.create("http://192.168.43.102:8080/",SplashService.class).getUserLiveData().observe(this, new Observer<User>() {
//            @Override
//            public void onChanged(User user) {
//                TextView txt = findViewById(R.id.txt);
//                txt.setText(new Gson().toJson(user));
//            }
//        });
//    }

}